package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Cookie和Session的获得
 * @author stone
 * @date 2022/08/08 15:50
 */
@RestController
public class CookieSessionController {

    @RequestMapping("cookies")
    public BaseRespVo cookies(HttpServletRequest request) {
        Cookie[] cookies = request.getCookies();
        //如果你想要拿到某个name对应的value就要遍历了
        for (Cookie cookie : cookies) {
            if ("ligenli".equals(cookie.getName())) {
                System.out.println("cookieValue:" + cookie.getValue());
            }
        }
        return BaseRespVo.ok(null);
    }

    @RequestMapping("session")
    public BaseRespVo session(HttpServletRequest request) {
        HttpSession session = request.getSession();
        return BaseRespVo.ok(null);
    }

    @RequestMapping("session2")
    public BaseRespVo session2(HttpSession session) {
        //HttpSession session = request.getSession();
        return BaseRespVo.ok(null);
    }
}
